<table id="card_change_info" data-options="fit:true"></table>
<div id="change_toolbar" style="padding:0 10px;">
	<input class="icon-add" type="button" value="换卡" onclick="javascript:openChangeWin()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<input class="icon-reload" type="button" value="刷新" onclick="javascript:flushChange()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<div style="float:right;margin-right:20px;">
		学号：<input style="text-align:center;" type="text" id="input_text_change">
		<input type="button" value="查询" onclick="javascript:findChange()"/>
	</div>
</div>
<script>
$(function(){
	$('#card_change_info').datagrid({
		url:'../cardInfoServlet?t='+new Date(),
		queryParams:{op:"selectChangeIdInfo"},
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'cid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'cid',title:'编号',width:100,align:'center',sortable:true},
			{field:'studentId',title:'学号',width:100,align:'center'}, 
			{field:'cname',title:'姓名',width:100,align:'center'},
			{field:'ctime',title:'换卡时间',width:100,align:'center'}
		]],
		toolbar:"#change_toolbar"
	});
});

function addChangeInfo(){
	var studentId = $.trim($("#studentId_change").val());
	var sname = $.trim($("#change_sname").val());
	var ctime = getDate();
	
	//为空判断
	if(studentId != "" && sname != "") {
		$.post("../cardInfoServlet?t="+new Date(),
			{op:"addChangeIdInfo",studentId:studentId,sname:sname,ctime:ctime},
			function(data){
			data = parseInt($.trim(data));
			if(data > 0) {
				$.messager.show({
					title:'成功提示',
					msg:'换卡信息添加成功!',
					timeout:3000,
					showType:'slide'
				});
				$("#studentId_change").val("");
				$("#change_sname").val("");
				$("#change_sclass").val("");
				$("#change_sdepartment").val("");
				
				$("#change_card").dialog("close");
				$('#card_change_info').datagrid("reload");
			} else {
				$.messager.alert('错误提示','换卡信息添加失败!','error');
			}
		});
	} else {
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交!',
			timeout:3000,
			showType:'slide'
		});
	}
}

function openChangeWin() {
	$("#change_card").dialog("open");
	$("#studentId_change").blur(function(){
		var studentId = $.trim($("#studentId_change").val());
		if(studentId!="") {
			$.post("../cardInfoServlet?"+new Date(),{op:"getStuInfo",studentId:studentId},function(data){
				if(parseInt($.trim(data))==0) {
					$.messager.alert('错误提示','没有信息!','error');
				} else {
					$("#change_sname").val(data.stuInfo1[0].sname);
					$("#change_sclass").val(data.stuInfo1[0].sclass);
					$("#change_sdepartment").val(data.stuInfo1[0].sdepartment);
				}
			},"json");
		} else {
			$.messager.show({
				title:'温馨提示',
				msg:'您输入的信息不正确，请确认后再提交!',
				timeout:3000,
				showType:'slide'
			});
		}
	});
}

function flushChange(){
	$('#card_change_info').datagrid("reload");
}

function findChange() {
	var studentId=$.trim($("#input_text_change").val());
	if(studentId!="") {
		$.post("../cardInfoServlet?"+new Date(),{op:"findChangeIdInfo",studentId:studentId},function(data){
			if(parseInt($.trim(data)) == 0) {
				$.messager.alert('错误提示','没有该信息!','error');
			}else{
				$("#card_change_info").datagrid("loadData",data.rows);
			}
		},"json");
	}else{
		$.messager.show({
			title : '温馨提示',
			msg : '您输入的信息不完整，请确认后再提交!',
			timeout : 3000,
			showType : 'slide'
		});
	}
}

//获取时间的方法
function getDate(){
	var date = new Date();
	var year = date.getFullYear().toString();
	var mouth = (date.getMonth()+1).toString();
	var ri = date.getDate().toString();
	d = year+"-"+mouth+"-"+ri;
	return d;
}

</script>
<div id="change_card" class="easyui-dialog" title="换卡" style="width:400px;height:280px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="studentId_change">学号：</label><input type="text" id="studentId_change">
		<br /> <br /> 
		<label for="sname">姓名：</label><input type="text" id="change_sname" disabled="disabled">
		<br /> <br />
		<label for="sclass">班级：</label><input type="text" id="change_sclass" disabled="disabled">
		<br /> <br />
		<label for="sdepartment">学院：</label><input type="text" id="change_sdepartment" disabled="disabled">
		<br /> <br />
		<input style="padding:5px 25px;" type="button" onclick="addChangeInfo()" value="换卡">
	</p>
</div>

